﻿using HalconDotNet;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using UserControl = System.Windows.Controls.UserControl;

namespace AppMachine.UserControls {
    /// <summary>
    /// UCCamera.xaml 的交互逻辑
    /// </summary>
    public partial class UCCamera : UserControl {
        public UCCamera() {
            InitializeComponent();
            App.Current.MainWindow.ContentRendered += MainWindow_ContentRendered;
        }

        private void MainWindow_ContentRendered(object? sender, EventArgs e) {
            if (this.IsLoaded) {
                App.Current.Dispatcher.Invoke(() => {
                    string tempFileName = "C:\\Users\\Administrator\\Pictures\\1.png";
                    var xx = File.Exists(tempFileName);

                    HFramegrabber tempFramegrabber = new("File", 1, 1, 0, 0, 0, 0, "default", -1, "default", -1, "default", tempFileName, "default", 1, -1);
                    HImage tempHImage = tempFramegrabber.GrabImage();
                    tempHImage.DispObj(hswControl.HalconWindow);
                });
            }
        }

        private void CameraInit() {
            string tempCameraID = "";
            string tempCameraParaName = "ExposureTimeAbs";
            double tempCameraParaValue = 40000.0;
            
            HOperatorSet.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "progressive", -1, "default", -1, "false", "default", tempCameraID, 0, -1, out HTuple hvAcqHandle1);
            HOperatorSet.SetFramegrabberParam(hvAcqHandle1, tempCameraParaName, tempCameraParaValue);

            HOperatorSet.GrabImage(out HObject hoImage, hvAcqHandle1);
            hoImage.DispObj(this.hswControl.HalconWindow);
        }

    }
}
